
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/15/2010 10:33:11
-- Generated from EDMX file: E:\DotNET Project\SecManage\src\SManage.S_DAL\Entities\SManageEntities.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [wlaq];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_Device_Mib2_interfaces]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_interfaces] DROP CONSTRAINT [FK_Device_Mib2_interfaces];
GO
IF OBJECT_ID(N'[dbo].[FK_Device_Mib2_ip]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_ip] DROP CONSTRAINT [FK_Device_Mib2_ip];
GO
IF OBJECT_ID(N'[dbo].[FK_Device_Mib2_system]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_system] DROP CONSTRAINT [FK_Device_Mib2_system];
GO
IF OBJECT_ID(N'[dbo].[FK_Mib2_interfaces_ifTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_interfaces_ifEntry] DROP CONSTRAINT [FK_Mib2_interfaces_ifTable];
GO
IF OBJECT_ID(N'[dbo].[FK_Mib2_ip_ipAddrTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_ip_ipAddrEntry] DROP CONSTRAINT [FK_Mib2_ip_ipAddrTable];
GO
IF OBJECT_ID(N'[dbo].[FK_Mib2_ip_ipNetToMediaTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_ip_ipNetToMediaEntry] DROP CONSTRAINT [FK_Mib2_ip_ipNetToMediaTable];
GO
IF OBJECT_ID(N'[dbo].[FK_Mib2_ip_ipRouteTable]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Mib2_ip_ipRouteEntry] DROP CONSTRAINT [FK_Mib2_ip_ipRouteTable];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Devices]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Devices];
GO
IF OBJECT_ID(N'[dbo].[Mib2_interfaces]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_interfaces];
GO
IF OBJECT_ID(N'[dbo].[Mib2_interfaces_ifEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_interfaces_ifEntry];
GO
IF OBJECT_ID(N'[dbo].[Mib2_ip]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_ip];
GO
IF OBJECT_ID(N'[dbo].[Mib2_ip_ipAddrEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_ip_ipAddrEntry];
GO
IF OBJECT_ID(N'[dbo].[Mib2_ip_ipNetToMediaEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_ip_ipNetToMediaEntry];
GO
IF OBJECT_ID(N'[dbo].[Mib2_ip_ipRouteEntry]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_ip_ipRouteEntry];
GO
IF OBJECT_ID(N'[dbo].[Mib2_system]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Mib2_system];
GO
IF OBJECT_ID(N'[dbo].[T_BaseInfomation]', 'U') IS NOT NULL
    DROP TABLE [dbo].[T_BaseInfomation];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Devices'
CREATE TABLE [dbo].[Devices] (
    [DeviceId] int IDENTITY(1,1) NOT NULL,
    [DeviceIpAddress] nchar(50)  NOT NULL
);
GO

-- Creating table 'Mib2_interfaces'
CREATE TABLE [dbo].[Mib2_interfaces] (
    [ifID] int IDENTITY(1,1) NOT NULL,
    [ifNumber] int  NULL,
    [Devices_DeviceId] int  NOT NULL
);
GO

-- Creating table 'Mib2_interfaces_ifEntry'
CREATE TABLE [dbo].[Mib2_interfaces_ifEntry] (
    [ifIndex] int IDENTITY(1,1) NOT NULL,
    [ifDescr] nchar(255)  NULL,
    [ifType] int  NULL,
    [ifMtu] int  NULL,
    [ifSpeed] bigint  NULL,
    [ifPhysAddress] nchar(20)  NULL,
    [ifAdminStatus] int  NULL,
    [ifOperStatus] int  NULL,
    [ifLastChange] bigint  NULL,
    [ifInOctets] bigint  NULL,
    [ifInUcastPkts] bigint  NULL,
    [ifInNUcastPkts] bigint  NULL,
    [ifInDiscards] bigint  NULL,
    [ifInErrors] bigint  NULL,
    [ifInUnknownProtos] bigint  NULL,
    [ifOutOctets] bigint  NULL,
    [ifOutUcastPkts] bigint  NULL,
    [ifOutNUcastPkts] bigint  NULL,
    [ifOutDiscards] bigint  NULL,
    [ifOutErrors] bigint  NULL,
    [ifOutQLen] bigint  NULL,
    [ifSpecific] nchar(255)  NULL,
    [Mib2_interfaces_ifID] int  NOT NULL
);
GO

-- Creating table 'Mib2_ip'
CREATE TABLE [dbo].[Mib2_ip] (
    [ipID] int IDENTITY(1,1) NOT NULL,
    [ipForwarding] int  NULL,
    [ipDefaultTTL] int  NULL,
    [ipInReceives] bigint  NULL,
    [ipInHdrErrors] bigint  NULL,
    [ipInAddrErrors] bigint  NULL,
    [ipForwDatagrams] bigint  NULL,
    [ipInUnknownProtos] bigint  NULL,
    [ipInDiscards] bigint  NULL,
    [ipInDelivers] bigint  NULL,
    [ipOutRequests] bigint  NULL,
    [ipOutDiscards] bigint  NULL,
    [ipOutNoRoutes] bigint  NULL,
    [ipReasmTimeout] int  NULL,
    [ipReasmReqds] bigint  NULL,
    [ipReasmOKs] bigint  NULL,
    [ipReasmFails] bigint  NULL,
    [ipFragOKs] bigint  NULL,
    [ipFragFails] bigint  NULL,
    [ipFragCreates] bigint  NULL,
    [ipRoutingDiscards] bigint  NULL,
    [Devices_DeviceId] int  NOT NULL
);
GO

-- Creating table 'Mib2_ip_ipAddrEntry'
CREATE TABLE [dbo].[Mib2_ip_ipAddrEntry] (
    [ipAdEntAddr] nchar(50)  NOT NULL,
    [ipAdEntIndex] int  NULL,
    [ipAdEntNetMask] nchar(50)  NULL,
    [ipAdEntBcastAddr] int  NULL,
    [ipAdEntReasmMaxSize] int  NULL,
    [Mib2_ip_ipID] int  NOT NULL
);
GO

-- Creating table 'Mib2_ip_ipNetToMediaEntry'
CREATE TABLE [dbo].[Mib2_ip_ipNetToMediaEntry] (
    [ipNetToMediaIfIndex] int  NOT NULL,
    [ipNetToMediaPhysAddress] nchar(20)  NULL,
    [ipNetToMediaNetAddress] nchar(20)  NULL,
    [ipNetToMediaType] nchar(10)  NULL,
    [Mib2_ip_ipID] int  NOT NULL
);
GO

-- Creating table 'Mib2_ip_ipRouteEntry'
CREATE TABLE [dbo].[Mib2_ip_ipRouteEntry] (
    [ipRouteDest] nchar(50)  NOT NULL,
    [ipRouteIfIndex] int  NULL,
    [ipRouteMetric1] int  NULL,
    [ipRouteMetric2] int  NULL,
    [ipRouteMetric3] int  NULL,
    [ipRouteMetric4] int  NULL,
    [ipRouteNextHop] nchar(50)  NULL,
    [ipRouteType] int  NULL,
    [ipRouteProto] int  NULL,
    [ipRouteAge] int  NULL,
    [ipRouteMask] nchar(50)  NULL,
    [ipRouteMetric5] int  NULL,
    [ipRouteInfo] nchar(255)  NULL,
    [Mib2_ip_ipID] int  NOT NULL
);
GO

-- Creating table 'Mib2_system'
CREATE TABLE [dbo].[Mib2_system] (
    [systemID] int IDENTITY(1,1) NOT NULL,
    [sysDescr] nchar(255)  NULL,
    [sysObjectID] nchar(255)  NULL,
    [sysUpTime] bigint  NULL,
    [sysContact] nchar(255)  NULL,
    [sysName] nchar(255)  NULL,
    [sysLocation] nchar(255)  NULL,
    [sysServices] int  NULL,
    [Devices_DeviceId] int  NOT NULL
);
GO

-- Creating table 'T_BaseInfomation'
CREATE TABLE [dbo].[T_BaseInfomation] (
    [sOid] char(40)  NOT NULL,
    [sObjectName] varchar(100)  NULL,
    [sOValue] varchar(200)  NULL,
    [tInDate] datetime  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [DeviceId] in table 'Devices'
ALTER TABLE [dbo].[Devices]
ADD CONSTRAINT [PK_Devices]
    PRIMARY KEY CLUSTERED ([DeviceId] ASC);
GO

-- Creating primary key on [ifID] in table 'Mib2_interfaces'
ALTER TABLE [dbo].[Mib2_interfaces]
ADD CONSTRAINT [PK_Mib2_interfaces]
    PRIMARY KEY CLUSTERED ([ifID] ASC);
GO

-- Creating primary key on [ifIndex] in table 'Mib2_interfaces_ifEntry'
ALTER TABLE [dbo].[Mib2_interfaces_ifEntry]
ADD CONSTRAINT [PK_Mib2_interfaces_ifEntry]
    PRIMARY KEY CLUSTERED ([ifIndex] ASC);
GO

-- Creating primary key on [ipID] in table 'Mib2_ip'
ALTER TABLE [dbo].[Mib2_ip]
ADD CONSTRAINT [PK_Mib2_ip]
    PRIMARY KEY CLUSTERED ([ipID] ASC);
GO

-- Creating primary key on [ipAdEntAddr] in table 'Mib2_ip_ipAddrEntry'
ALTER TABLE [dbo].[Mib2_ip_ipAddrEntry]
ADD CONSTRAINT [PK_Mib2_ip_ipAddrEntry]
    PRIMARY KEY CLUSTERED ([ipAdEntAddr] ASC);
GO

-- Creating primary key on [ipNetToMediaIfIndex] in table 'Mib2_ip_ipNetToMediaEntry'
ALTER TABLE [dbo].[Mib2_ip_ipNetToMediaEntry]
ADD CONSTRAINT [PK_Mib2_ip_ipNetToMediaEntry]
    PRIMARY KEY CLUSTERED ([ipNetToMediaIfIndex] ASC);
GO

-- Creating primary key on [ipRouteDest] in table 'Mib2_ip_ipRouteEntry'
ALTER TABLE [dbo].[Mib2_ip_ipRouteEntry]
ADD CONSTRAINT [PK_Mib2_ip_ipRouteEntry]
    PRIMARY KEY CLUSTERED ([ipRouteDest] ASC);
GO

-- Creating primary key on [systemID] in table 'Mib2_system'
ALTER TABLE [dbo].[Mib2_system]
ADD CONSTRAINT [PK_Mib2_system]
    PRIMARY KEY CLUSTERED ([systemID] ASC);
GO

-- Creating primary key on [sOid] in table 'T_BaseInfomation'
ALTER TABLE [dbo].[T_BaseInfomation]
ADD CONSTRAINT [PK_T_BaseInfomation]
    PRIMARY KEY CLUSTERED ([sOid] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Devices_DeviceId] in table 'Mib2_interfaces'
ALTER TABLE [dbo].[Mib2_interfaces]
ADD CONSTRAINT [FK_Device_Mib2_interfaces]
    FOREIGN KEY ([Devices_DeviceId])
    REFERENCES [dbo].[Devices]
        ([DeviceId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Device_Mib2_interfaces'
CREATE INDEX [IX_FK_Device_Mib2_interfaces]
ON [dbo].[Mib2_interfaces]
    ([Devices_DeviceId]);
GO

-- Creating foreign key on [Devices_DeviceId] in table 'Mib2_ip'
ALTER TABLE [dbo].[Mib2_ip]
ADD CONSTRAINT [FK_Device_Mib2_ip]
    FOREIGN KEY ([Devices_DeviceId])
    REFERENCES [dbo].[Devices]
        ([DeviceId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Device_Mib2_ip'
CREATE INDEX [IX_FK_Device_Mib2_ip]
ON [dbo].[Mib2_ip]
    ([Devices_DeviceId]);
GO

-- Creating foreign key on [Devices_DeviceId] in table 'Mib2_system'
ALTER TABLE [dbo].[Mib2_system]
ADD CONSTRAINT [FK_Device_Mib2_system]
    FOREIGN KEY ([Devices_DeviceId])
    REFERENCES [dbo].[Devices]
        ([DeviceId])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Device_Mib2_system'
CREATE INDEX [IX_FK_Device_Mib2_system]
ON [dbo].[Mib2_system]
    ([Devices_DeviceId]);
GO

-- Creating foreign key on [Mib2_interfaces_ifID] in table 'Mib2_interfaces_ifEntry'
ALTER TABLE [dbo].[Mib2_interfaces_ifEntry]
ADD CONSTRAINT [FK_Mib2_interfaces_ifTable]
    FOREIGN KEY ([Mib2_interfaces_ifID])
    REFERENCES [dbo].[Mib2_interfaces]
        ([ifID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Mib2_interfaces_ifTable'
CREATE INDEX [IX_FK_Mib2_interfaces_ifTable]
ON [dbo].[Mib2_interfaces_ifEntry]
    ([Mib2_interfaces_ifID]);
GO

-- Creating foreign key on [Mib2_ip_ipID] in table 'Mib2_ip_ipAddrEntry'
ALTER TABLE [dbo].[Mib2_ip_ipAddrEntry]
ADD CONSTRAINT [FK_Mib2_ip_ipAddrTable]
    FOREIGN KEY ([Mib2_ip_ipID])
    REFERENCES [dbo].[Mib2_ip]
        ([ipID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Mib2_ip_ipAddrTable'
CREATE INDEX [IX_FK_Mib2_ip_ipAddrTable]
ON [dbo].[Mib2_ip_ipAddrEntry]
    ([Mib2_ip_ipID]);
GO

-- Creating foreign key on [Mib2_ip_ipID] in table 'Mib2_ip_ipNetToMediaEntry'
ALTER TABLE [dbo].[Mib2_ip_ipNetToMediaEntry]
ADD CONSTRAINT [FK_Mib2_ip_ipNetToMediaTable]
    FOREIGN KEY ([Mib2_ip_ipID])
    REFERENCES [dbo].[Mib2_ip]
        ([ipID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Mib2_ip_ipNetToMediaTable'
CREATE INDEX [IX_FK_Mib2_ip_ipNetToMediaTable]
ON [dbo].[Mib2_ip_ipNetToMediaEntry]
    ([Mib2_ip_ipID]);
GO

-- Creating foreign key on [Mib2_ip_ipID] in table 'Mib2_ip_ipRouteEntry'
ALTER TABLE [dbo].[Mib2_ip_ipRouteEntry]
ADD CONSTRAINT [FK_Mib2_ip_ipRouteTable]
    FOREIGN KEY ([Mib2_ip_ipID])
    REFERENCES [dbo].[Mib2_ip]
        ([ipID])
    ON DELETE CASCADE ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Mib2_ip_ipRouteTable'
CREATE INDEX [IX_FK_Mib2_ip_ipRouteTable]
ON [dbo].[Mib2_ip_ipRouteEntry]
    ([Mib2_ip_ipID]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------